﻿
Partial Class WebForm_ExecVolunteer
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0

        sql.AppendFormat(" Select * From Volunteer Where VolunteerID = '{0}' ", Me.txtNewID.Text)
        If dat.GetData(sql).Rows.Count > 0 Then
            MyObj.ShowMessage(Me.txtNewID.Text + " 此志工帳號已存在")
            Return
        End If

        sql.Length = 0

        sql.AppendFormat(" Update Volunteer Set VolunteerID=@NewID where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update ImportVolunteerRecord Set VolunteerID=@NewID, IdentificationID = @NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update EnlistTrainingRecord Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update HonorCert Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update HonorCertApplication Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update MonthlyVolunteerStat Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update OtherTrainingRecord Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update OtherWorkRecord Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update TrainingRegister Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        ' sql.AppendFormat(" Update tvolunteer Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update UserCustomOrganizationAuth Set UserID=@NewID Where UserID = @OrgID; ")
        sql.AppendFormat(" Update UserOrganizationAuth Set UserID=@NewID Where UserID = @OrgID; ")
        sql.AppendFormat(" Update UserProgramAuth Set UserID=@NewID Where UserID = @OrgID; ")
        sql.AppendFormat(" Update UserRoleAuth Set UserID=@NewID Where UserID = @OrgID; ")
        sql.AppendFormat(" Update VBook Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update VBookApplication Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update VolunteerApplication Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update VolunteerInsurance Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update VolunteerWorkTime Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update VOrganizationMapping Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update WishOrganization Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update WorkHourRecord Set VolunteerID=@NewID Where VolunteerID = @OrgID; ")
        sql.AppendFormat(" Update WorkHeader Set LeaderID=@NewID Where LeaderID = @OrgID; ")
        sql.AppendFormat(" Update OtherOrganizationMapping Set UserID=@NewID Where UserID = @OrgID; ")
        sql.AppendFormat(" Update AwardRecord Set VolunteerID=@NewID Where VolunteerID=@OrgID; ")
        sql.AppendFormat(" Update EnlistRecord Set VolunteerID=@NewID Where VolunteerID=@OrgID; ")
        sql.AppendFormat(" Update EnlistRecordApplication Set VolunteerID=@NewID Where VolunteerID=@OrgID; ")
        sql.AppendFormat(" Update GroupVolunteerMapping Set VolunteerID=@NewID Where VolunteerID=@OrgID; ")
        sql.AppendFormat(" Update ImportWorkHourRecord Set VolunteerID=@NewID Where VolunteerID=@OrgID; ")

        sql.AddWithValue("NewID", Me.txtNewID.Text)
        sql.AddWithValue("OrgID", Me.txtOrgID.Text)


        Try
            dat.AccData(sql)
            MyObj.ShowMessage("更新成功")
        Catch ex As Exception
            MyObj.ShowMessage("更新失敗")
        End Try


    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0

        sql.AppendFormat(" Delete From Volunteer where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From ImportVolunteerRecord where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From EnlistTrainingRecord where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From HonorCert where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From HonorCertApplication where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From MonthlyVolunteerStat where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From OtherTrainingRecord where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From OtherWorkRecord where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From TrainingRegister where VolunteerID = @VolunteerID; ")
        ' sql.AppendFormat(" Delete From tvolunteer where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From UserCustomOrganizationAuth where UserID = @VolunteerID; ")
        sql.AppendFormat(" Delete From UserOrganizationAuth where UserID = @VolunteerID; ")
        sql.AppendFormat(" Delete From UserProgramAuth where UserID = @VolunteerID; ")
        sql.AppendFormat(" Delete From UserRoleAuth where UserID = @VolunteerID; ")
        sql.AppendFormat(" Delete From VBook where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From VBookApplication where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From VolunteerApplication where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From VolunteerInsurance where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From VolunteerWorkTime where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From VOrganizationMapping where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From WishOrganization where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From WorkHourRecord where VolunteerID = @VolunteerID; ")
        sql.AppendFormat(" Delete From WorkHeader where LeaderID = @VolunteerID; ")
        sql.AppendFormat(" Delete From OtherOrganizationMapping where UserID= @VolunteerID; ")
        sql.AppendFormat(" Delete From AwardRecord Where VolunteerID=@VolunteerID; ")
        sql.AppendFormat(" Delete From EnlistRecord Where VolunteerID=@VolunteerID; ")
        sql.AppendFormat(" Delete From EnlistRecordApplication Where VolunteerID=@VolunteerID; ")
        sql.AppendFormat(" Delete From GroupVolunteerMapping Where VolunteerID=@VolunteerID; ")
        sql.AppendFormat(" Delete From ImportWorkHourRecord Where VolunteerID=@VolunteerID; ")

        sql.AddWithValue("VolunteerID", Me.txtDeleteID.Text)

        Try
            dat.AccData(sql)
            MyObj.ShowMessage("刪除成功")
        Catch ex As Exception
            MyObj.ShowMessage("刪除失敗")
        End Try


    End Sub
End Class
